# -*- encoding: utf-8 -*-
"""
Copyright 2011,2012 Ernesto Angel Celis de la Fuente 
<celisdelafuente@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from google.appengine.ext import db


class Route(db.Model):
    """Storage for routes of transport and metadata
    Properties
    route_code: Uniquely identifies each route, usually routes have a code
    or number assignated by public transportation authorities, use that.
    color: Color that identifies each route (vehicle or signs color).
    descripcion: Description of the route, like key stops.
    vehicle_type: The type of vehicles. (Bus, Microbus, Other; it could change)
    """
    code = db.StringProperty(required=True)
    color = db.StringProperty(required=True)
    description = db.StringProperty(multiline=True)
    vehicle = db.StringProperty()
    votes = db.IntegerProperty()
    geometry = db.TextProperty()

'''
TODO Change this, you got lost with Ancestors and Entity keys, this is an
ancestor so perhaps, you can use the route_code here as the ancestor.
'''
def route_key(route_ancestor=None):
    """Constructs a datastore key for a Route entity with route_code."""
    return db.Key.from_path('Route', route_ancestor or '01')




class RouteStop(db.Model):
    """Storage for Routes stops.
    Properties
    geometry:	Latitude and logindude tuple for Google Maps API
    description:	Key buildings or common references for stops.
    votes: how much support the stop has.
    route: route_code. This is a foreign key.
    """
    description = db.StringProperty()
    votes = db.IntegerProperty()
    geometry = db.GeoPtProperty()
    # One-to-Many Reference to Route. I also call it "stops" insted of default
    route = db.ReferenceProperty(Route,
                                collection_name='stops')


